package org.fude;


import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@SpringBootApplication
@ServletComponentScan
@MapperScan("org.fude.dao")
@EnableScheduling
public class FudeApplicationBootstrap extends WebMvcConfigurerAdapter{

	public static void main(String[] args) {
		SpringApplication.run(FudeApplicationBootstrap.class, args);
	}
	
	@Override
    public void addCorsMappings(CorsRegistry registry) {
		 registry.addMapping("/**")  
         .allowedOrigins("*")  
         .allowCredentials(true)  
         .allowedMethods("GET", "POST", "DELETE", "PUT")  
         .allowedHeaders("*")
         .maxAge(3600);  
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		//将默认静态资源路径配置到和html一样的路径中（templates），以便于统一管理
		registry.addResourceHandler("/**").addResourceLocations("classpath:/templates/");
		super.addResourceHandlers(registry);
	}
	
}
